package com.qianfeng.test.task;

import android.os.AsyncTask;
import android.text.TextUtils;
import android.widget.BaseAdapter;

import com.alibaba.fastjson.JSONObject;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.qianfeng.test.bean.AppBean;
import com.qianfeng.test.bean.menu_bean.ListEntity;
import com.qianfeng.test.bean.menu_bean.MenuBean;
import com.qianfeng.test.utils.HttpUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 15-7-20.
 */
public class MenuTask extends AsyncTask<String ,Void,List<ListEntity>>{
//    private MenuDownLoadEnd menuDownLoadEnd;
    private BaseAdapter baseAdapter;
    private List<ListEntity>listEntity;
    public MenuTask(BaseAdapter baseAdapter, List<ListEntity> listEntity) {
        this.baseAdapter = baseAdapter;
        this.listEntity = listEntity;
    }

    @Override
    protected List<ListEntity> doInBackground(String... params) {
        List<ListEntity> list = new ArrayList<>();
        String result = HttpUtils.getDataFromService(params[0]);
        if(!TextUtils.isEmpty(result)){
            MenuBean menu = JSONObject.parseObject(result, MenuBean.class);
            if(menu!=null&&menu.getResult()!=null){//问题
       //         menuList = app.getResult().getData();//
                list.addAll(menu.getResult().getList());//出问题

            }
        }
        return list;
    }

    @Override
    protected void onPostExecute(List<ListEntity> listEntitys) {
        super.onPostExecute(listEntitys);
        if(listEntitys!=null&&listEntitys.size()>0){
            System.out.print("MenuTask....进来了");
            listEntity.addAll(listEntitys);//出问题
            baseAdapter.notifyDataSetChanged();

        }

    }
//    public void setOnMenuDownLoadEnd(MenuDownLoadEnd menuDownLoadEnd){
//        this.menuDownLoadEnd = menuDownLoadEnd;
//    }
//    public interface MenuDownLoadEnd{
//        void onMenuDownLoadEnd(List<ListEntity>listEntity);
//    }
}
